﻿<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:ck="clr-namespace:WPFDemo.Presentation.Controls.CheckBox"
    xmlns:s="clr-namespace:System;assembly=mscorlib"
    xmlns:theme="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero"
    >

    <Style x:Key="CheckRadioFocusVisual">
        <Setter Property="Control.Template">
            <Setter.Value>
                <ControlTemplate>
                    <Rectangle Margin="14,0,0,0"
                     StrokeThickness="1"
                     Stroke="Black"
                     StrokeDashArray="1 2"
                     SnapsToDevicePixels="true"/>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
    <ControlTemplate x:Key="AccessTextCheckBoxControlTemplate" TargetType="ck:AccessTextCheckBox">
        <BulletDecorator Background="Transparent"
                                 SnapsToDevicePixels="true">
            <BulletDecorator.Bullet>
                <theme:BulletChrome Background="{TemplateBinding Background}"
                            BorderBrush="{TemplateBinding BorderBrush}"
                            RenderMouseOver="{TemplateBinding IsMouseOver}"
                            RenderPressed="{TemplateBinding IsPressed}"
                            IsChecked="{TemplateBinding IsChecked}"/>
            </BulletDecorator.Bullet>
            <AccessText x:Name="AccessText"
                  Text="{TemplateBinding Content}"
                  Margin="{TemplateBinding Padding}"
                  VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                  HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                  SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
                  TextWrapping="{TemplateBinding TextWrapping}"
                  TextAlignment="{TemplateBinding TextAlignment}"
                  TextTrimming="{TemplateBinding TextTrimming}"
                        />
        </BulletDecorator>
        <ControlTemplate.Triggers>
            <Trigger Property="HasContent" Value="true">
                <Setter Property="FocusVisualStyle" Value="{StaticResource CheckRadioFocusVisual}"/>
                <Setter Property="Padding" Value="4,0,0,0"/>
            </Trigger>
            <Trigger Property="IsEnabled" Value="false">
                <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>
    <Style TargetType="ck:AccessTextCheckBox" BasedOn="{StaticResource {x:Type CheckBox}}">
        <Setter Property="Template" Value="{StaticResource AccessTextCheckBoxControlTemplate}" />
    </Style>

    <Style TargetType="{x:Type ck:StarCheckBox}">
        <Setter Property="Margin" Value="2pt,0,2pt,0" />
        <Setter Property="VerticalAlignment" Value="Center" />
        <Setter Property="StarMaxWidth" Value="16" />
        <Setter Property="StarMaxHeight" Value="16" />
        <Setter Property="Control.Template">
            <Setter.Value>
                <ControlTemplate TargetType="CheckBox">
                    <BulletDecorator Background="#00FFFFFF" SnapsToDevicePixels="True">
                        <BulletDecorator.Bullet>
                            <Image x:Name="StarButton"
                     MaxWidth="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ck:StarCheckBox}}, Path=StarMaxWidth}"
                     MaxHeight="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ck:StarCheckBox}}, Path=StarMaxHeight}"
                     Source="/WPFDemo.Presentation;component/Resources/star_DIS.png"
                     />
                        </BulletDecorator.Bullet>
                        <Grid Background="{TemplateBinding Panel.Background}" >
                            <ContentPresenter RecognizesAccessKey="True"
                                Content="{TemplateBinding ContentControl.Content}"
                                ContentTemplate="{TemplateBinding ContentControl.ContentTemplate}"
                                ContentStringFormat="{TemplateBinding ContentControl.ContentStringFormat}"
                                Margin="{TemplateBinding Control.Padding}"
                                HorizontalAlignment="{TemplateBinding Control.HorizontalContentAlignment}"
                                VerticalAlignment="{TemplateBinding Control.VerticalContentAlignment}"
                                SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}"
                                              />
                        </Grid>
                    </BulletDecorator>
                    <ControlTemplate.Triggers>
                        <Trigger Property="ContentControl.HasContent" Value="True">
                            <Setter Property="Control.Padding" Value="4,0,0,0" />
                        </Trigger>
                        <Trigger Property="UIElement.IsEnabled" Value="False">
                            <Setter Property="Source" TargetName="StarButton" Value="/WPFDemo.Presentation;component/Resources/star_DIS.png" />
                            <Setter Property="TextElement.Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}" />
                        </Trigger>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter Property="Cursor" Value="Hand" />
                        </Trigger>
                        <Trigger Property="IsChecked" Value="True">
                            <Setter Property="Source" TargetName="StarButton" Value="/WPFDemo.Presentation;component/Resources/star.png" />
                        </Trigger>
                        <Trigger Property="IsPressed" Value="True">
                            <Setter Property="Source" TargetName="StarButton" Value="/WPFDemo.Presentation;component/Resources/star_HOT.png" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

</ResourceDictionary>

